﻿using System.Collections;
using System.Collections.Generic;
using BaseSyntax.Values.StringTest.Yaml.Configs;

namespace BaseSyntax.Values.StringTest.Yaml.Parsers
{
	public class TextParser:IParser
	{
		public Dictionary<string, object> Parse(
			Dictionary<string, object> dUnity, 
			string fileId, 
			Dictionary<string, object> parent, 
			Dictionary<string, object> dCorona)
		{

			var dSingleUnity = dUnity[fileId] as Dictionary<string, object>;

			if (dSingleUnity == null)
			{
				return null;
			}
			
			var dSingleCorona = new Dictionary<string, object>();
			
			var children = parent["children"] as ArrayList;
			
			// image组件作为可视组件，直接作为children
			if (children != null)
			{
				children.Add(fileId);
			}

			dCorona[fileId] = dSingleCorona;

			dSingleCorona["ctype"] = CoronaMap.GetCoronaType("Text");
			
			var color = dSingleUnity["m_Color"] as Dictionary<string, object>;

			if (color != null)
			{
				var dColor = new Dictionary<string, float>();
					
				dColor["r"] = float.Parse((string) color["r"]);
				dColor["g"] = float.Parse((string) color["g"]);
				dColor["b"] = float.Parse((string) color["b"]);
				dColor["a"] = float.Parse((string) color["a"]);

				dSingleCorona["color"] = dColor;
			}

			dSingleCorona["text"] = (string) dSingleUnity["m_Text"];
			
			return dSingleCorona;
		}
	}
}